﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace CPA
{
    class fmv_03_intro
    {
        Texture2D backdrop;
        SpriteBatch spriteBatch;
        // Intro animation in here
        GameState gameState = GameState.FmvIntro;
        List<character> characters;
        string[] text = new string[4];
        int step = 1;
        bool EnterDown = true;

        public fmv_03_intro(List<character> characters, Texture2D backdrop, SpriteBatch spriteBatch)
        {
            this.characters = characters;
            this.backdrop = backdrop;
            this.spriteBatch = spriteBatch;
        }

        public void update() 
        {
            KeyboardState state = Keyboard.GetState();
            GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
            if (state.IsKeyUp(Keys.Enter) && (gamePadState.Buttons.A == ButtonState.Released)) EnterDown = false;
                    characters[0].x = -1000;
                    characters[1].x = -1000;
                    characters[2].x = -1000;
                    switch (step)
            {
                case 1: //Fromage
                    text[0] = "\"You still think you can resist?";
                    text[1] = "You've already fallen.\"";
                    text[2] = "";
                    text[3] = "";
                    characters[0].talk(text);
                    if ((state.IsKeyDown(Keys.Enter) || (gamePadState.Buttons.A == ButtonState.Pressed)) && !EnterDown)
                    {
                        step++;
                        EnterDown = true;
                    }
                    break;
                case 2: // Fromage
                    characters[0].talk();
                    text[0] = "\"Your freedom is over.\"";
                    text[1] = "";
                    text[2] = "";
                    text[3] = "";
                    characters[0].talk(text);
                    if ((state.IsKeyDown(Keys.Enter) || (gamePadState.Buttons.A == ButtonState.Pressed)) && !EnterDown)
                    {
                        characters[0].talk();
                        step++;
                        EnterDown = true;
                    }
                    break;
                case 3: // Famine
                    text[0] = "\"How...?";
                    text[1] = "What are you...?\"";
                    text[2] = "";
                    text[3] = "";
                    characters[1].talk(text);
                    if ((state.IsKeyDown(Keys.Enter) || (gamePadState.Buttons.A == ButtonState.Pressed)) && !EnterDown)
                    {
                        characters[1].talk();
                        step++;
                        EnterDown = true;
                    }
                    break;
                case 4: // Death
                    text[0] = "\"For us to lose....";
                    text[1] = "...you are no normal human...\"";
                    text[2] = "";
                    text[3] = "";
                    characters[2].talk(text);
                    if ((state.IsKeyDown(Keys.Enter) || (gamePadState.Buttons.A == ButtonState.Pressed)) && !EnterDown)
                    {
                        characters[2].talk();
                        step++;
                        EnterDown = true;
                    }
                    break;
                case 5: // Fromage
                    characters[0].talk();
                    text[0] = "\"I am Dr. Fenetres Fromage.";
                    text[1] = "Your new MASTER!\"";
                    text[2] = "";
                    text[3] = "";
                    characters[0].talk(text);
                    if ((state.IsKeyDown(Keys.Enter) || (gamePadState.Buttons.A == ButtonState.Pressed)) && !EnterDown)
                    {
                        characters[0].talk();
                        step++;
                        EnterDown = true;
                    }
                    break;
                default:
                    gameState = GameState.Level01;
                    break;
            }
        }

        public void draw() 
        {
            spriteBatch.Draw(backdrop, new Rectangle(0, 0, 800, 480), Color.White);
            foreach (character c in characters)
            {
                c.draw();
            }
        }

        public GameState get_state() 
        {
            return this.gameState;
        }
    }
}
